﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;//Please add references
namespace DAL
{
	/// <summary>
	/// 数据访问类:T_WorkEmployeeExam
	/// </summary>
	public partial class T_WorkEmployeeExam
	{
		public T_WorkEmployeeExam()
		{}
		#region  BasicMethod



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Model.T_WorkEmployeeExam model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_WorkEmployeeExam(");
			strSql.Append("EmployeeId,EmployeeCardNO,EmployeeName,ExamID,ExamName,TypeCode,TypeName,ExecuteDate,ExamDateB,ExamDateE,Score,EmployeeExamStatus,Executor,Accept_Count,Bellow_Score,Department,ExamDateW,Bkcs,BKbz,iszw,isksEnd,ErrorSL,ErrorFruit,IsMnLx)");
			strSql.Append(" values (");
			strSql.Append("@EmployeeId,@EmployeeCardNO,@EmployeeName,@ExamID,@ExamName,@TypeCode,@TypeName,@ExecuteDate,@ExamDateB,@ExamDateE,@Score,@EmployeeExamStatus,@Executor,@Accept_Count,@Bellow_Score,@Department,@ExamDateW,@Bkcs,@BKbz,@iszw,@isksEnd,@ErrorSL,@ErrorFruit,@IsMnLx)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@EmployeeId", SqlDbType.Int,4),
					new SqlParameter("@EmployeeCardNO", SqlDbType.VarChar,20),
					new SqlParameter("@EmployeeName", SqlDbType.VarChar,20),
					new SqlParameter("@ExamID", SqlDbType.Int,4),
					new SqlParameter("@ExamName", SqlDbType.VarChar,100),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.NVarChar,50),
					new SqlParameter("@ExecuteDate", SqlDbType.VarChar,50),
					new SqlParameter("@ExamDateB", SqlDbType.VarChar,8),
					new SqlParameter("@ExamDateE", SqlDbType.VarChar,8),
					new SqlParameter("@Score", SqlDbType.Float,8),
					new SqlParameter("@EmployeeExamStatus", SqlDbType.Int,4),
					new SqlParameter("@Executor", SqlDbType.VarChar,50),
					new SqlParameter("@Accept_Count", SqlDbType.Int,4),
					new SqlParameter("@Bellow_Score", SqlDbType.Int,4),
					new SqlParameter("@Department", SqlDbType.NVarChar,50),
					new SqlParameter("@ExamDateW", SqlDbType.VarChar,8),
					new SqlParameter("@Bkcs", SqlDbType.Int,4),
					new SqlParameter("@BKbz", SqlDbType.Int,4),
					new SqlParameter("@iszw", SqlDbType.TinyInt,1),
					new SqlParameter("@isksEnd", SqlDbType.TinyInt,1),
					new SqlParameter("@ErrorSL", SqlDbType.Int,4),
					new SqlParameter("@ErrorFruit", SqlDbType.Int,4),
					new SqlParameter("@IsMnLx", SqlDbType.TinyInt,1)};
			parameters[0].Value = model.EmployeeId;
			parameters[1].Value = model.EmployeeCardNO;
			parameters[2].Value = model.EmployeeName;
			parameters[3].Value = model.ExamID;
			parameters[4].Value = model.ExamName;
			parameters[5].Value = model.TypeCode;
			parameters[6].Value = model.TypeName;
			parameters[7].Value = model.ExecuteDate;
			parameters[8].Value = model.ExamDateB;
			parameters[9].Value = model.ExamDateE;
			parameters[10].Value = model.Score;
			parameters[11].Value = model.EmployeeExamStatus;
			parameters[12].Value = model.Executor;
			parameters[13].Value = model.Accept_Count;
			parameters[14].Value = model.Bellow_Score;
			parameters[15].Value = model.Department;
			parameters[16].Value = model.ExamDateW;
			parameters[17].Value = model.Bkcs;
			parameters[18].Value = model.BKbz;
			parameters[19].Value = model.iszw;
			parameters[20].Value = model.isksEnd;
			parameters[21].Value = model.ErrorSL;
			parameters[22].Value = model.ErrorFruit;
			parameters[23].Value = model.IsMnLx;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Model.T_WorkEmployeeExam model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_WorkEmployeeExam set ");
			strSql.Append("EmployeeId=@EmployeeId,");
			strSql.Append("EmployeeCardNO=@EmployeeCardNO,");
			strSql.Append("EmployeeName=@EmployeeName,");
			strSql.Append("ExamID=@ExamID,");
			strSql.Append("ExamName=@ExamName,");
			strSql.Append("TypeCode=@TypeCode,");
			strSql.Append("TypeName=@TypeName,");
			strSql.Append("ExecuteDate=@ExecuteDate,");
			strSql.Append("ExamDateB=@ExamDateB,");
			strSql.Append("ExamDateE=@ExamDateE,");
			strSql.Append("Score=@Score,");
			strSql.Append("EmployeeExamStatus=@EmployeeExamStatus,");
			strSql.Append("Executor=@Executor,");
			strSql.Append("Accept_Count=@Accept_Count,");
			strSql.Append("Bellow_Score=@Bellow_Score,");
			strSql.Append("Department=@Department,");
			strSql.Append("ExamDateW=@ExamDateW,");
			strSql.Append("Bkcs=@Bkcs,");
			strSql.Append("BKbz=@BKbz,");
			strSql.Append("iszw=@iszw,");
			strSql.Append("isksEnd=@isksEnd,");
			strSql.Append("ErrorSL=@ErrorSL,");
			strSql.Append("ErrorFruit=@ErrorFruit,");
			strSql.Append("IsMnLx=@IsMnLx");
			strSql.Append(" where WorkEmployeeExamId=@WorkEmployeeExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@EmployeeId", SqlDbType.Int,4),
					new SqlParameter("@EmployeeCardNO", SqlDbType.VarChar,20),
					new SqlParameter("@EmployeeName", SqlDbType.VarChar,20),
					new SqlParameter("@ExamID", SqlDbType.Int,4),
					new SqlParameter("@ExamName", SqlDbType.VarChar,100),
					new SqlParameter("@TypeCode", SqlDbType.Int,4),
					new SqlParameter("@TypeName", SqlDbType.NVarChar,50),
					new SqlParameter("@ExecuteDate", SqlDbType.VarChar,50),
					new SqlParameter("@ExamDateB", SqlDbType.VarChar,8),
					new SqlParameter("@ExamDateE", SqlDbType.VarChar,8),
					new SqlParameter("@Score", SqlDbType.Float,8),
					new SqlParameter("@EmployeeExamStatus", SqlDbType.Int,4),
					new SqlParameter("@Executor", SqlDbType.VarChar,50),
					new SqlParameter("@Accept_Count", SqlDbType.Int,4),
					new SqlParameter("@Bellow_Score", SqlDbType.Int,4),
					new SqlParameter("@Department", SqlDbType.NVarChar,50),
					new SqlParameter("@ExamDateW", SqlDbType.VarChar,8),
					new SqlParameter("@Bkcs", SqlDbType.Int,4),
					new SqlParameter("@BKbz", SqlDbType.Int,4),
					new SqlParameter("@iszw", SqlDbType.TinyInt,1),
					new SqlParameter("@isksEnd", SqlDbType.TinyInt,1),
					new SqlParameter("@ErrorSL", SqlDbType.Int,4),
					new SqlParameter("@ErrorFruit", SqlDbType.Int,4),
					new SqlParameter("@IsMnLx", SqlDbType.TinyInt,1),
					new SqlParameter("@WorkEmployeeExamId", SqlDbType.Int,4)};
			parameters[0].Value = model.EmployeeId;
			parameters[1].Value = model.EmployeeCardNO;
			parameters[2].Value = model.EmployeeName;
			parameters[3].Value = model.ExamID;
			parameters[4].Value = model.ExamName;
			parameters[5].Value = model.TypeCode;
			parameters[6].Value = model.TypeName;
			parameters[7].Value = model.ExecuteDate;
			parameters[8].Value = model.ExamDateB;
			parameters[9].Value = model.ExamDateE;
			parameters[10].Value = model.Score;
			parameters[11].Value = model.EmployeeExamStatus;
			parameters[12].Value = model.Executor;
			parameters[13].Value = model.Accept_Count;
			parameters[14].Value = model.Bellow_Score;
			parameters[15].Value = model.Department;
			parameters[16].Value = model.ExamDateW;
			parameters[17].Value = model.Bkcs;
			parameters[18].Value = model.BKbz;
			parameters[19].Value = model.iszw;
			parameters[20].Value = model.isksEnd;
			parameters[21].Value = model.ErrorSL;
			parameters[22].Value = model.ErrorFruit;
			parameters[23].Value = model.IsMnLx;
			parameters[24].Value = model.WorkEmployeeExamId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int WorkEmployeeExamId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkEmployeeExam ");
			strSql.Append(" where WorkEmployeeExamId=@WorkEmployeeExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@WorkEmployeeExamId", SqlDbType.Int,4)
			};
			parameters[0].Value = WorkEmployeeExamId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string WorkEmployeeExamIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_WorkEmployeeExam ");
			strSql.Append(" where WorkEmployeeExamId in ("+WorkEmployeeExamIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkEmployeeExam GetModel(int WorkEmployeeExamId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 WorkEmployeeExamId,EmployeeId,EmployeeCardNO,EmployeeName,ExamID,ExamName,TypeCode,TypeName,ExecuteDate,ExamDateB,ExamDateE,Score,EmployeeExamStatus,Executor,Accept_Count,Bellow_Score,Department,ExamDateW,Bkcs,BKbz,iszw,isksEnd,ErrorSL,ErrorFruit,IsMnLx from T_WorkEmployeeExam ");
			strSql.Append(" where WorkEmployeeExamId=@WorkEmployeeExamId");
			SqlParameter[] parameters = {
					new SqlParameter("@WorkEmployeeExamId", SqlDbType.Int,4)
			};
			parameters[0].Value = WorkEmployeeExamId;

			Model.T_WorkEmployeeExam model=new Model.T_WorkEmployeeExam();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.T_WorkEmployeeExam DataRowToModel(DataRow row)
		{
			Model.T_WorkEmployeeExam model=new Model.T_WorkEmployeeExam();
			if (row != null)
			{
				if(row["WorkEmployeeExamId"]!=null && row["WorkEmployeeExamId"].ToString()!="")
				{
					model.WorkEmployeeExamId=int.Parse(row["WorkEmployeeExamId"].ToString());
				}
				if(row["EmployeeId"]!=null && row["EmployeeId"].ToString()!="")
				{
					model.EmployeeId=int.Parse(row["EmployeeId"].ToString());
				}
				if(row["EmployeeCardNO"]!=null)
				{
					model.EmployeeCardNO=row["EmployeeCardNO"].ToString();
				}
				if(row["EmployeeName"]!=null)
				{
					model.EmployeeName=row["EmployeeName"].ToString();
				}
				if(row["ExamID"]!=null && row["ExamID"].ToString()!="")
				{
					model.ExamID=int.Parse(row["ExamID"].ToString());
				}
				if(row["ExamName"]!=null)
				{
					model.ExamName=row["ExamName"].ToString();
				}
				if(row["TypeCode"]!=null && row["TypeCode"].ToString()!="")
				{
					model.TypeCode=int.Parse(row["TypeCode"].ToString());
				}
				if(row["TypeName"]!=null)
				{
					model.TypeName=row["TypeName"].ToString();
				}
				if(row["ExecuteDate"]!=null)
				{
					model.ExecuteDate=row["ExecuteDate"].ToString();
				}
				if(row["ExamDateB"]!=null)
				{
					model.ExamDateB=row["ExamDateB"].ToString();
				}
				if(row["ExamDateE"]!=null)
				{
					model.ExamDateE=row["ExamDateE"].ToString();
				}
				if(row["Score"]!=null && row["Score"].ToString()!="")
				{
					model.Score=decimal.Parse(row["Score"].ToString());
				}
				if(row["EmployeeExamStatus"]!=null && row["EmployeeExamStatus"].ToString()!="")
				{
					model.EmployeeExamStatus=int.Parse(row["EmployeeExamStatus"].ToString());
				}
				if(row["Executor"]!=null)
				{
					model.Executor=row["Executor"].ToString();
				}
				if(row["Accept_Count"]!=null && row["Accept_Count"].ToString()!="")
				{
					model.Accept_Count=int.Parse(row["Accept_Count"].ToString());
				}
				if(row["Bellow_Score"]!=null && row["Bellow_Score"].ToString()!="")
				{
					model.Bellow_Score=int.Parse(row["Bellow_Score"].ToString());
				}
				if(row["Department"]!=null)
				{
					model.Department=row["Department"].ToString();
				}
				if(row["ExamDateW"]!=null)
				{
					model.ExamDateW=row["ExamDateW"].ToString();
				}
				if(row["Bkcs"]!=null && row["Bkcs"].ToString()!="")
				{
					model.Bkcs=int.Parse(row["Bkcs"].ToString());
				}
				if(row["BKbz"]!=null && row["BKbz"].ToString()!="")
				{
					model.BKbz=int.Parse(row["BKbz"].ToString());
				}
				if(row["iszw"]!=null && row["iszw"].ToString()!="")
				{
					model.iszw=int.Parse(row["iszw"].ToString());
				}
				if(row["isksEnd"]!=null && row["isksEnd"].ToString()!="")
				{
					model.isksEnd=int.Parse(row["isksEnd"].ToString());
				}
				if(row["ErrorSL"]!=null && row["ErrorSL"].ToString()!="")
				{
					model.ErrorSL=int.Parse(row["ErrorSL"].ToString());
				}
				if(row["ErrorFruit"]!=null && row["ErrorFruit"].ToString()!="")
				{
					model.ErrorFruit=int.Parse(row["ErrorFruit"].ToString());
				}
				if(row["IsMnLx"]!=null && row["IsMnLx"].ToString()!="")
				{
					model.IsMnLx=int.Parse(row["IsMnLx"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select WorkEmployeeExamId,EmployeeId,EmployeeCardNO,EmployeeName,ExamID,ExamName,TypeCode,TypeName,ExecuteDate,ExamDateB,ExamDateE,Score,EmployeeExamStatus,Executor,Accept_Count,Bellow_Score,Department,ExamDateW,Bkcs,BKbz,iszw,isksEnd,ErrorSL,ErrorFruit,IsMnLx ");
			strSql.Append(" FROM T_WorkEmployeeExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" WorkEmployeeExamId,EmployeeId,EmployeeCardNO,EmployeeName,ExamID,ExamName,TypeCode,TypeName,ExecuteDate,ExamDateB,ExamDateE,Score,EmployeeExamStatus,Executor,Accept_Count,Bellow_Score,Department,ExamDateW,Bkcs,BKbz,iszw,isksEnd,ErrorSL,ErrorFruit,IsMnLx ");
			strSql.Append(" FROM T_WorkEmployeeExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_WorkEmployeeExam ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.WorkEmployeeExamId desc");
			}
			strSql.Append(")AS Row, T.*  from T_WorkEmployeeExam T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "T_WorkEmployeeExam";
			parameters[1].Value = "WorkEmployeeExamId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

